package br.gendi.core;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

public class Configuracoes {

	
	public static Properties loadProxy() {
		Properties prop = new Properties();
	    FileInputStream fis = null;
		try {
			fis = new FileInputStream("proxy.xml");
		} catch (FileNotFoundException e) {
			try {
				new File("proxy.xml").createNewFile();
			} catch (IOException e1) {	}
		}
	    try {
			prop.loadFromXML(fis);
		} catch (IOException e) {	}
	    return prop;
	}

	public static void salvarProxy(boolean ativo, String host, String port, String user, String pass) {
		Properties prop = new Properties();
	    prop.setProperty("ativo", ativo?"true":"false");
	    prop.setProperty("host", host);
	    prop.setProperty("port", port);
	    prop.setProperty("user", user);
	    prop.setProperty("password", pass);
	    FileOutputStream fos = null;
		try {
			fos = new FileOutputStream("proxy.xml");
		} catch (FileNotFoundException e) {
			try {
				new File("proxy.xml").createNewFile();
			} catch (IOException e1) {	}
		}
	    try {
			prop.storeToXML(fos, "Proxy Configuration");
		} catch (IOException e) {	}
	    try {
			fos.close();
		} catch (IOException e) {	}
	}
}
